package commands

import (
	"github.com/urfave/cli"

	"../flags"
	"../utils"
)

// Dev - dev action
func Dev(config utils.Config) cli.Command {
	return cli.Command{
		Name:     "dev",
		Usage:    "Goto develop branch",
		Category: "COMMON COMMANDS",
		Flags: []cli.Flag{
			flags.Flags["path"],
		},
		Action: makeAction(config, devAction),
	}
}

func devAction(conf utils.Config, git utils.Git, context *cli.Context) error {
	result, err := utils.LoadConfig(conf, git, "config")
	if err != nil {
		return err
	}

	var name string
	name, err = result.String("global", "dev")
	if err != nil {
		return err
	}

	_, err = git.Execute(
		[]string{"checkout", name},
	)
	return err
}
